package cn.stylefeng.guns.modular.api.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.cms.entity.AppNotice;
import cn.stylefeng.guns.modular.cms.model.params.*;
import cn.stylefeng.guns.modular.cms.model.result.*;
import cn.stylefeng.guns.modular.cms.service.*;
import cn.stylefeng.guns.utils.MemberTokenUtil;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 内容管理相关接口
 *
 * @author yzb
 * @Date 2019-11-07 15:57:43
 */
@Controller
@RequestMapping("/api/cms")
@Api(tags = "内容管理相关接口")
@CrossOrigin
public class ApiCmsController extends BaseController {

    @Autowired
    private AdService adService;
    @Autowired
    private AboutUsService aboutUsService;
    @Autowired
    private ContactUsService contactUsService;
    @Autowired
    private HelpService helpService;
    @Autowired
    private AppNoticeService appNoticeService;
    @Autowired
    private FeedbackService feedbackService;
    @Autowired
    private LawService lawService;

    /**
     * 查询轮播图
     *
     * @author yzb
     * @Date 2019-11-07
     */
    @ResponseBody
    @RequestMapping(value = "/ad/list", method = RequestMethod.GET)
    @ApiOperation(value = "查询轮播图", notes = "根据轮播图位置查询")
    @ApiImplicitParam(name = "apId", value = "位置编号（1-用户首页，2-特色课程，3-外包任务，11-企业首页）", dataType = "Integer")
    public ResponseData list(Integer apId) {
        AdParam adParam = new AdParam();
        if (apId != null) {
            adParam.setApId(apId);
        }
        List<AdResult> ads = adService.findListBySpec(adParam);
        return ResponseData.success(ads);
    }


    /**
     * 关于我们
     *
     * @author yzb
     * @Date 2020-01-17
     */
    @ResponseBody
    @RequestMapping(value = "/aboutUs/detail", method = RequestMethod.GET)
    @ApiOperation(value = "关于我们", notes = "关于我们")
    public ResponseData aboutUsDetail() {
        AboutUsParam param = new AboutUsParam();
        param.setStatus("ENABLE");
        AboutUsResult result = null;
        List<AboutUsResult> results = aboutUsService.findListBySpec(param);
        if (results.size() > 0) {
            result = results.get(0);
        }
        return ResponseData.success(result);
    }

    /**
     * 联系我们
     *
     * @author yzb
     * @Date 2020-01-17
     */
    @ResponseBody
    @RequestMapping(value = "/contactUs/detail", method = RequestMethod.GET)
    @ApiOperation(value = "联系我们", notes = "联系我们")
    public ResponseData contactUs() {
        ContactUsParam param = new ContactUsParam();
        param.setStatus("ENABLE");
        ContactUsResult result = null;
        List<ContactUsResult> results = contactUsService.findListBySpec(param);
        if (results.size() > 0) {
            result = results.get(0);
        }
        return ResponseData.success(result);
    }

    /**
     * 平台说明内容、各种协议
     *
     * @author yzb
     * @Date 2020-01-17
     */
    @ResponseBody
    @RequestMapping(value = "/help/detail", method = RequestMethod.GET)
    @ApiOperation(value = "平台说明内容（协议、说明等）", notes = "平台说明内容（协议、说明等）")
    public ResponseData helpDetail(Integer categoryId) {
        HelpParam param = new HelpParam();
        param.setStatus("ENABLE");
        param.setCategoryId(categoryId);
        List<HelpResult> results = helpService.findListBySpec(param);
        return ResponseData.success(results);
    }


    /**
     * 查询公告列表
     *
     * @author yzb
     * @Date 2020-01-18
     */
    @ResponseBody
    @RequestMapping(value = "/notice/list", method = RequestMethod.GET)
    @ApiOperation(value = "查询公告列表", notes = "查询公告列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页数量", dataType = "Integer", paramType = "query")
    })
    public ResponseData getNoticeList() {
        AppNoticeParam param = new AppNoticeParam();
        LayuiPageInfo pageInfo = appNoticeService.findPageBySpec(param);
        return ResponseData.success(pageInfo);
    }


    /**
     * 公告详情
     *
     * @author yzb
     * @Date 2020-01-17
     */
    @ResponseBody
    @RequestMapping(value = "/notice/detail", method = RequestMethod.GET)
    @ApiOperation(value = "公告详情", notes = "公告详情")
    @ApiImplicitParam(name = "noticeId", value = "公告ID", dataType = "Integer", paramType = "query")
    public ResponseData noticeDetail(Integer noticeId) {
        AppNotice notice = appNoticeService.getById(noticeId);
        return ResponseData.success(notice);
    }


    /**
     * 添加意见反馈
     *
     * @author yzb
     * @Date 2020-01-17
     */
    @ResponseBody
    @RequestMapping(value = "/feedback/add", method = RequestMethod.GET)
    @ApiOperation(value = "添加意见反馈", notes = "添加意见反馈")
    @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header")
    public ResponseData addFeedback(FeedbackParam param) {
        //取得当前Token登录者会员的ID
        int memberId = MemberTokenUtil.getMemberId();
        param.setMemberId(memberId);
        feedbackService.add(param);
        return ResponseData.success();
    }


    /**
     * 查询法律列表
     *
     * @author yzb
     * @Date 2022-05-17
     */
    @ResponseBody
    @RequestMapping(value = "/law/list", method = RequestMethod.GET)
    @ApiOperation(value = "查询法律列表", notes = "查询法律列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页数量", dataType = "Integer", paramType = "query")
    })
    public ResponseData getLawList(LawParam param) {
        LayuiPageInfo pageInfo = lawService.findPageBySpec(param.setStatus("ENABLE"));
        return ResponseData.success(pageInfo);
    }


    /**
     * 法律详情
     *
     * @author yzb
     * @Date 2022-05-17
     */
    @ResponseBody
    @RequestMapping(value = "/law/detail", method = RequestMethod.GET)
    @ApiOperation(value = "法律详情", notes = "法律详情")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "query")
    public ResponseData lawDetail(Integer id) {
        LawResult result = lawService.findBySpec(new LawParam().setId(id));
        return ResponseData.success(result);
    }

}



